package llama.config;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

public class PropertyConfigurator implements IConfigurator {
	
	@Override
	public void save(Map<String,String> data, String file) throws IOException {
		Properties prop = new Properties();
		FileOutputStream fos = null;
		
		prop.putAll(data);
		
		fos = new FileOutputStream(file);
		prop.store(fos, null);
		fos.close();
		
		System.out.println(file +" created by PropertyConfigurator");
	}

	@Override
	public Map<String,String> load(String file) throws IOException {
		Map<String,String> data = null;
		
		Properties prop = new Properties();
		FileInputStream fis = null;

		fis = new FileInputStream(file);
		prop.load(fis);
		
		data = (Map)prop.clone();
		
		fis.close();

		return data;
	}

}
